package com.chen.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chen.common.R;
import com.chen.dto.SetmealDto;
import com.chen.service.SetmealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/setmeal")
public class SetmealController {
    @Autowired
    private SetmealService setmealService;

    /**
     * 套餐分页查询
     * @param page
     * @param pageSize
     * @param name
     * @return
     */
    @GetMapping("/page")
    public R<Page<SetmealDto>> setmealPage(Integer page, Integer pageSize, String name){
        return setmealService.setmealPage(page,pageSize,name);
    }

    /**
     * 新增套餐
     * @param setmealDto
     * @return
     */
    @PostMapping
    public R<String> addSetmeal(@RequestBody SetmealDto setmealDto){
        return setmealService.addSetmeal(setmealDto);
    }

    /**
     * 删除套餐
     * @param ids
     * @return
     */
    @DeleteMapping
    public R<String> deleteSetmael(Long[] ids){
        return setmealService.deleteSetmael(ids);
    }

    /**
     * 修改套餐状态
     * @param status
     * @param ids
     * @return
     */
    @PostMapping("/status/{status}")
    public R<String> updateStatus(@PathVariable Integer status,@RequestParam Long[] ids){
        return setmealService.updateStatus(status,ids);
    }

    /**
     * 回显要修改的数据
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public R<SetmealDto> echoSetmeal(@PathVariable Long id){
        return setmealService.echoSetmeal(id);
    }

    /**
     * 修改套餐
     * @param setmealDto
     * @return
     */
    @PutMapping
    public R<String> updateSetmeal(@RequestBody SetmealDto setmealDto){
        return setmealService.updateSetmeal(setmealDto);
    }
}
